import { formatDateByFmt, getWeek } from '@/utils/dateUtil.js';

export const Add_APPOINTMENT = '0';
export const EDIT_APPOINTMENT = '1';
export const AGAIN_APPOINTMENT = '2';
export const RE_APPOINTMENT = '3';

export const OPERATE_STORE = 'store';
export const OPERATE_USER = 'user';

export const ORDER_DURATION = [
  {
    label: '1小时',
    value: 60,
  },
  {
    label: '2小时',
    value: 120,
  },
  {
    label: '3小时',
    value: 180,
  },
  {
    label: '4小时',
    value: 240,
  },
];

export const TAB_STATUS = [
  {
    name: '进行中',
    status: '0',
  },
  {
    name: '已完成',
    status: '1',
  },
  {
    name: '已取消',
    status: '2',
  },
  {
    name: '客户未到',
    status: '3',
  },
];

// 格式化到期日期
export const formatToShopDate = (data, format='MM月dd日') => {
  const monthDate = formatDateByFmt(data.time, format);
  const week = getWeek(data.time);
  data['monthDate'] = monthDate;
  data['week'] = week;
  return data;
};

export const getQueryDates = (filterDate, days) => {
  const newDays = [];
  let tempIndex = days.length;
  days.forEach((day, dayIndex) => {
    const time = day.time;
    const date = formatDateByFmt(time, 'dd');
    const week = getWeek(time);
    day['date'] = date;
    day['week'] = week;

    if (time === filterDate) {
      tempIndex = dayIndex;
    }
    if (dayIndex >= tempIndex) {
      newDays.push({ ...day });
    }
  });

  const pageIndex = parseInt(newDays.length / 3) + (newDays.length % 3 === 0 ? 0 : 1);

  const queryDays = [];
  for (let i = 0; i < pageIndex; i++) {
    const itemList = [];
    for (let j = i * 3; j < i * 3 + 3; j++) {
      if (j < newDays.length) {
        itemList.push(newDays[j]);
      }
    }
    queryDays.push(itemList);
  }
  return queryDays;
};

export const getWorkDates = (days) => {
  const timeList = [];
  days.forEach((item, index) => {
    timeList.push(item.time);
  });
  return timeList.join(',');
};

export const PAGE_SIZE = 20;
export const PAGE_INDEX = 1;
